package top.hkyzf.study.leetcode.string;

import org.junit.Test;

import java.util.Arrays;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/13 0013 11:44
 * @version V1.0
 */
public class 最大二进制奇数_2864 {
    public String maximumOddBinaryNumber(String s) {
        char[] chars = s.toCharArray();
        int index = -1;
        for (char aChar : chars) {
            if (aChar == 49) {
                index++;
            }
        }
        if (index == -1) {
            return s;
        }
        for (int i = 0; i < index; i++) {
            chars[i] = 49;
        }
        for (int i = index; i < chars.length-1; i++) {
            chars[i] = 48;
        }
        chars[chars.length-1] = 49;
        return new String(chars);
    }

    @Test
    public void testMaximumBinary () {
        String s = "01011111010";
        System.out.println(maximumOddBinaryNumber(s));
    }
}
